package com.qzd.proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * jdk的代理类
 */
public class JdkProXyStudy implements InvocationHandler {
    private IPerson tager;

    public IPerson getInstance(IPerson tager) {
        this.tager = tager;
        Class<?> clazz = tager.getClass();
        return (IPerson) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(this.tager, args);
        after();
        return invoke;
    }

    private void after() {
        System.out.println("找人学习完成");
    }

    private void before() {
        System.out.println("找人学习准备");
    }
}
